package httpapi

import (
	"io"
	"os/exec"

	"away.wei/minidevpos/global"
)

type DevopsWS struct{}

var (
	webshellApp = new(webshell)
	shell       = &exec.Cmd{
		Stdout: webshellApp,
		Stderr: webshellApp,
	}
	stdin io.WriteCloser
)

type webshell struct {
	io.Writer
}

func (*webshell) Write(p []byte) (n int, err error) {
	global.DevOpsEventAPP.EmitJson("webshell", string(p))
	return 0, nil
}

func (*DevopsWS) WebShell(args string) {
	if stdin == nil {
		stdin, _ = shell.StdinPipe()
	}
	stdin.Write([]byte(args))
	stdin.Close()
	shell.Run()
}
func (*DevopsWS) Deploy(args string) {

}
